package com.gitee.zycra.union.api.service;

import com.gitee.zycra.union.api.common.bo.CommonResult;
import com.gitee.zycra.union.api.common.param.AddMockInstanceParam;
import com.gitee.zycra.union.api.common.param.UpdateInstanceCaseParam;
import com.gitee.zycra.union.api.common.vo.InstanceCaseVO;
import com.gitee.zycra.union.api.common.vo.InstanceVO;
import com.gitee.zycra.union.api.manager.ApiMockInstanceManager;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author zycra
 */
@Slf4j
@Service
public class ApiMockInstanceService {

    @Autowired
    private ApiMockInstanceManager apiMockInstanceManager;

    /**
     * 添加mock模板实例
     *
     * @param addMockInstanceParam 模板实例参数
     * @return 添加结果
     */
    public CommonResult<String> addMockInstance(AddMockInstanceParam addMockInstanceParam) {
        apiMockInstanceManager.addMockInstance(addMockInstanceParam);
        return CommonResult.success();
    }

    /**
     * 更新mock模板实例
     *
     * @param id           模板实例ID
     * @param instanceName 模板实例名称
     * @return 更新结果
     */
    public CommonResult<String> updateMockInstance(Long id, String instanceName) {
        apiMockInstanceManager.updateMockInstance(id, instanceName);
        return CommonResult.success();
    }

    /**
     * 删除mock模板实例
     *
     * @param id 模板实例ID
     * @return 删除结果
     */
    public CommonResult<String> deleteMockInstance(Long id) {
        apiMockInstanceManager.deleteMockInstance(id);
        return CommonResult.success();
    }

    /**
     * 查询mock模板实例
     *
     * @param templateId 模板ID
     * @return 查询结果
     */
    public CommonResult<List<InstanceVO>> selectMockInstance(Long templateId) {
        return CommonResult.success(apiMockInstanceManager.selectMockInstance(templateId));
    }

    /**
     * 查询mock模板实例期望
     *
     * @param instanceId  模板实例ID
     * @return 添加结果
     */
    public CommonResult<List<InstanceCaseVO>> selectMockInstanceCase(Long instanceId) {
        return CommonResult.success(apiMockInstanceManager.selectMockInstanceCase(instanceId));
    }

    /**
     * 更新模板实例期望
     *
     * @param updateInstanceCaseParam 更新参数
     * @return 删除结果
     */
    public CommonResult<String> updateMockInstanceCase(UpdateInstanceCaseParam updateInstanceCaseParam) {
        apiMockInstanceManager.updateMockInstanceCase(updateInstanceCaseParam);
        return CommonResult.success();
    }
}
